<style>
	* {padding:0px;margin:0px;box-sizing:border-box;outline:none;}
	.header{width:100%;}
	.header .header_info{display: table;margin:0 auto;	max-width: 1200px;width: 100%;}
	.header .header_info .left {text-align: left;display: table-cell;}
	.header .header_info .right {text-align: right;display: table-cell;vertical-align:middle;margin-right:20px;}
	.header .header_info .right .text {border:3px solid #ff4401;width:420px;height:30px;background:#fff;padding-left:80px;color:#666}
	.header .header_info .right .sub {width:80px;height:30px;background:#ff4401;color:#fff;font-family:微软雅黑;font-weight:bold;letter-spacing:10px;text-align:center;border:1px solid #ff4401;cursor:pointer;}
	.header .header_info .right .sel {width:80px;height:25px;position:relative;left:82px;border:none;background:#f5f5f5;color:#666;padding-left:5px;}
	
	.title{margin-top:20px;}
	.title .nav_cart {width:1200px;margin:0 auto;}
	.nav_cart ul{border-bottom:1px solid #ccc;}
	.nav_cart ul li{display:inline-block;padding:10px;}
	.nav_cart ul li a{text-decoration:none;color:#000;font-weight:bold;}
	.nav_cart i{color:#000;font-style:normal;font-weight:bold;}
	.line{border-bottom:2px solid #eee;}
	.nav_cart em a{font-style:normal;float:right;color:blue;font-size:12px;text-decoration:none;}
	.nav_cart ul li{width:1200px;margin-top:10px;font-size:12px;padding:10px 200px;}
	.nav_cart ul li em{font-style:normal;}
	.nav_cart ul li b{font-style:normal;color:#ff5500;}
	.cheaddr{background:#fff0e8;border:1px solid #ff5500;width:1200px;padding:10px 200px;margin-top:10px;}
	.cheaddr em{font-size:14px;font-weight:bold;}
	.cheaddr b{display:inline-block;}
	.cart .cart_detail{width:1200px;margin:0 auto;}
	table{font-size:12px;}
	table tr td{padding:10px;}	
	table tr td a img{border:1px solid #ccc;float:left;margin-right:10px;}	
	table tr td p {text-align:left;}	
	table tr td p a{text-decoration:none;color:#111;}	
	table tr td p a:hover{text-decoration:underline;color:#ff4401;}	
	table .td1{width:400px;text-align:center;}	
	table .td1 em{font-style:normal;}	
	table .td2{width:100px;text-align:center;}	
	table .td3{width:100px;text-align:center;}	
	table .td4{width:200px;text-align:center;}	
	table .td5{width:200px;text-align:center;}	
	
	
	table .gd1{width:100px;text-align:center;}	
	table .gd1 em{font-style:normal;}	
	table .gd2{width:100px;text-align:center;}	
	table .gd3{width:100px;text-align:center;}	
	table .gd4{width:480px;text-align:center;}	
	table .gd5{width:180px;text-align:center;}	
	table  td a{text-decoration:none;color:#000}	
	table  td a:hover{color:#ff4401}	
	table .gd6 input{background:#ff4401;width:100px;color:#fff;font-size:20px;text-align:center;font-family:微软雅黑;letter-spacing:2px;border:none;height:40px;}	
	table .gd6 input:hover{cursor:pointer;}	
	
	
	.count{width:20px;}
	.minus{ width:20px;background:#f0f0f0;border:none;cursor:pointer}	
	.minus:hover{ border:1px solid #ff4401;color:#ff4401}	
	.plus{width:20px;background:#f0f0f0;border:none;cursor:pointer}	
	.plus:hover{border:1px solid #ff4401;color:#ff4401}	
	.text_box{width:30px;border:none;border:1px solid #ccc;color:#333}
	
	.total{font-style:normal;}
</style> 
   <script src="<?php echo backweb_JS_URL;?>jquery-1.9.1.min.js"></script>
<script>

	$(function (){
			//初始化总价
			setTotal();
			//失去焦点出发
			$("input").blur(function(){
				setTotal();

				var index = $(this).parent().attr("id");
				var index2 = $(this).attr("id");
				if(index == index2){
					per_count = $(".tt .td4").children("input:text[id="+index+"]").val();
					per = $(".tt .td3").children("input[id="+index+"]").val();
					var index = $(this).parent().attr("id");
					$(".tt .td5 ").children("em[id="+index+"]").text((per_count*per).toFixed(2));
				} 
			})
			//+按钮
			$(".tt .plus").click(function(){
				var index = $(this).index(this);
				var text_value = $(this).parent().find('input[class=text_box]');
				if(!isNaN(text_value)) alert('不是数字');
					text_value.val(parseInt(text_value.val()) + 1);
				setTotal();


				var index = $(this).parent().attr("id");
				var index2 = $(this).attr("id");
				if(index == index2){
					per_count = $(".tt .td4").children("input:text[id="+index+"]").val();
					per = $(".tt .td3").children("input[id="+index+"]").val();
					var index = $(this).parent().attr("id");
//					$(".tt .td5 .total").children("input[id="+index+"]").val(per_count*per);
					$(".tt .td5 ").children("em[id="+index+"]").text((per_count*per).toFixed(2));
				} 
				
				
			})
			$(".tt .minus").click(function(){
				var text_value = $(this).parent().find('input:text[class=text_box]');
				if(text_value.val() > 0){
					text_value.val(parseInt(text_value.val()) - 1);
				}
				setTotal();
				var index = $(this).parent().attr("id");
				var index2 = $(this).attr("id");
				if(index == index2){
					per_count = $(".tt .td4").children("input:text[id="+index+"]").val();
					per = $(".tt .td3").children("input[id="+index+"]").val();
					var index = $(this).parent().attr("id");
					$(".tt .td5 ").children("em[id="+index+"]").text((per_count*per).toFixed(2));
				} 
			})

		//全选触发
		$(".selectall").click(function (){
				if($(this).is(':checked')){
					$("input[class*='che']").each(function(){
						$(this).prop("checked",true);
						$(".selectall").prop("checked",true);
						setTotal();
					})
					
				}else{
					$("input[class*='che']").each(function(){
						$(this).prop("checked",false);
						$(".selectall").prop("checked",false);
						setTotal();
					})
				}
		})
		//反选触发
		$("#reverse").click(function(){
			$(".selectall").attr("checked",false);
			$("input[class*='che']").each(function(){
				if($(this).prop("checked")){
					$(this).prop("checked", false); 
				}
				else{
					$(this).prop("checked", true); 
				}
			})

			setTotal();
		})
		
		$(".che").click(function(){
			setTotal();
		})
		
		//获得总价
		function setTotal(){
				var s=0; 
				var count = 0;
			    $("table[class *= tt]").each(function(){
			      if($(this).find("input[class *= 'che']").is(":checked")){
				      s+=parseInt($(this).find('input[class*=text_box]').val())*parseFloat($(this).find('td[class*=td3]').text()); 
				      count += parseInt($(this).find('input[class*=text_box]').val());
			      }
			    }); 

			    if(count <= 0){
					$("#pay").css("background","#e1e1e1");
					$("#pay").attr("disabled","true");
					$("#pay").val("无商品");
				}else{
					$("#pay").css("background","#ff4401");
					$("#pay").removeAttr("disabled");
					$("#pay").val("创建订单");
				}

			    
				$("#price").html(s.toFixed(2)); 
			    $("#count").html(count);
				$("#total_price").text((express_price()+s).toFixed(2));
				$(".priceTotal").val((express_price()+s).toFixed(2));
			}

			$(".del").click(function (){
				var id = $(this).attr("id");
				var table_id = $(".tt").attr("id");
				$.ajax({
					url:'./index.php?r=order/cartdel&goods_id='+id,
					type:'post',
					data:{"type":"delpro"},
					success:function(data){
						if(data == 1){
							$('.tt[id='+table_id+']').remove();
						}else{
							alert('移出购物车失败');
						}
					},
					error:function (){
						alert('操作失败');
					}
				});
			})

			$("#update").click(function (){
//				var formdata = $("#f").serializeArray();
//				alert(formdata);
//				$.ajax({
//					url:'./index.php?r=order/cartupd',
//					type:'post',
//					data:{"type":"updpro","aa":formdata},
//					success:function(data){
//						alert(data);
//						if(data == 1){
//							alert('更新成功');
//						}else{
//							alert('更新失败');
//						}
//					},
//					error:function (){
//						alert('操作失败');
//					}
//				});
//				window.location.reload();
			})
			$.fn.serializeObject = function() { 
				var o = {}; 
				var a = this.serializeArray(); 
					$.each(a, function() { 
						if (o[this.name]) { 
							if (!o[this.name].push) { 
							o[this.name] = [ o[this.name] ]; 
							} 
							o[this.name].push(this.value || ''); 
						} else { 
							o[this.name] = this.value || ''; 
						} 
					}); 
				return o; 
			} 

		$("#pay").click(function (){
			window.location.href="./index.php?r=order/account";
		})
		$("#addr li").click(function(){
			var index = $(this).index();
			$(this).siblings().removeClass();
			$(this).addClass("cheaddr");
			$("#addr li input[id!="+index+"]").removeAttr("checked");
			$("#addr li input[id="+index+"]").attr("checked","checked").siblings().removeAttr("checked");
			$("#hd").val($("#addr li input:radio[name='addr']:checked").val());
			
//			$("#addr li input:radio[val='+index+']").eq(index).attr("checked","true");
//			$("#addr li input:radio[name='addr']").eq(index).attr("checked","true").siblings().removeAttr("checked");
			
		})
		
		//运费
		function express_price(){
			if($("#express").find("option:selected").val() == 0){
				return 0;
			}
			else if($("#express").find("option:selected").val() == 1){
				return 10;
			}else if($("#express").find("option:selected").val() == 2){
				return 22;
			}else if($("#express").find("option:selected").val() == 3){
				return 40;
			}
		} 

		$("#express").click(function (){
			setTotal();
		})
	
	})
</script>

<div class="header">
	<div class="header_info">
		<div class="left">
			<div class="box"><a href="./index.php"><img src="<?php echo  IMG_URL?>order_confirm.png" /></a></div>
		</div>
		<div class="right">	
			<div class="box">
				<select class="sel"><option value="1">商品</option><option value="2">店铺</option></select><input type="text" name="search"  class="text" /><input type="submit" name="send" value="搜索" class="sub" />
			</div>
		</div>
	</div>
</div>

	 	<form action="./index.php?r=order/orderconfirm"  method="post" id="f" />
	 	<input type="hidden" name="unid" value="<?php echo uniqid();?>" />
 <div class="title" style="margin-bottom:10px;">
 	<div class="nav_cart" >
		<i>确认收货地址</i>
		<em><a href="./index.php?r=user/userinfo&user_id=<?php echo Yii::app()->user->id;?>">管理收货地址</a></em>
		<div class="line"></div>
		<ul id="addr">
			<?php foreach ($addr_info as $_k => $_v) {?>
				<li class="<?php if($_v['addr_default'] == 1) echo 'cheaddr';?>"><b>配送至　</b><input   type="radio" value="<?php echo $_v['addr_id']?>"    name="addr" id="<?php echo $_k;?>"/><em><?php echo $_v['addr_pro']?> <?php echo $_v['addr_city']?> <?php echo $_v['addr_country']?> <?php echo $_v['addr_details']?> (<?php echo $_v['addr_reciver_name'];?> 收) <?php echo $_v['addr_tel']?></em></li>
				
			<?php }?>
		<input id="hd" type="hidden"  name="addr" />
		</ul>
 	</div>
 </div>
 <div class="cart" >
 	<div class="cart_detail">
	 	<table style="margin-bottom:30px;">
	 		<tr >
	 			<td class="td1">商品信息</td>
	 			<td class="td2">店铺信息</td>
	 			<td class="td3">单价(元)</td>
	 			<td class="td4">数量	</td>
	 			<td class="td5" >小计(元)</td>
	 		</tr>
	 	</table>
	 	
 		<?php foreach($goods_info as $_k => $_v){?>
	 	<table  class="tt" style="border:1px solid #ccc;background:#fcfcfc;margin-top:20px;margin-bottom:20px;"  id="<?php echo $_v['goods_id']?>" >
			<tr>
	 			<td style="width:120px;text-align:right;"><input type="checkbox" disabled="true" <?php if($_v['active'] == 1) echo "checked='checked'";?>  value="<?php echo $_v['goods_id'];?>"    class="che"  style="vertical-align:middle;text-align:left;"   /></td>
	 			<td class="td1"><a href="#"><img style="text-align:left;" src="<?php echo $_v['goods_thumbnail_url']?>" width="89" height="89" /></a><p><a href="#"><?php echo $_v['goods_name']?></a></p></td>
				<td class="td2"><?php echo $_v['brand_id']?></td>
				
				<td class="td3"   id="<?php echo $_v['goods_id']?>" ><input type="hidden" class="per"   value="<?php echo $_v['goods_price']?>"  id="<?php echo $_v['goods_id']?>" name="price_per[]" /><?php echo $_v['goods_price']?></td>
				<td class="td4" id="<?php echo $_v['goods_id']?>" >
					<input type="button" value="-" class="minus"  id="<?php echo $_v['goods_id']?>" />
					<input type="hidden" name="goods_ids[]" value="<?php echo $_v['goods_id']?>"  />
 					<input type="text" class="text_box" name="cart_goods_count[]"  value="<?php echo $_v['cart_goods_count']?>" id="<?php echo $_v['goods_id']?>"    />
					<input type="button" value="+" class="plus"  id="<?php echo $_v['goods_id']?>"   />
				</td>
<!--				<td class="td5"  id="<?php echo $_v['goods_id']?>"><em class="total" ><input type="text" readonly value=""  id="<?php echo $_v['goods_id']?>" /></em></td>-->
				<td class="td5"  id="<?php echo $_v['goods_id']?>"><em class="total"  id="<?php echo $_v['goods_id']?>"><?php echo  sprintf("%.2f",$_v['cart_goods_count']*$_v['goods_price']);?></em></td>
				<td class="td6" >　　　　</td>
			</tr>	 	
	 	</table>
	 	<?php }?>
	 	
	 	<table style="background:#f2f7ff" >
	 		<tr >
	 			<td>给卖家留言：<textarea  name="message"  style="border:1px solid #8ab6dd;width:420px;font-size:12px;"; placeholder="此项为选填"></textarea></td>
	 			<td style="width:600px;">配送快递
	 				<select style="padding:2px 5px;width:100px;font-size:12px;" id="express" name="express">
	 					<option value="1">快递10元</option>
	 					<option value="2">顺丰22元</option>
	 					<option value="3">EMS40元</option>
	 				</select>
	 			</td>
	 			<td class="gd5" >合计(不含运费)<i style="color:#ff4401;font-style:normal;font-size:15px;font-weight:bold;">￥<em style="font-style:normal;" id="price">0.00</em></i></td>
	 			
	 	</tr>
	 	</table >
	 	<table style="background:#e5e5e5" >
	 		<tr >
	 			<td style="width:140px;">
	 			</td>
	 			<td class="gd1"></td>
	 			<td class="gd2"></td>
	 			<td class="gd3"></td>
	 			<td class="gd4" >已选<i style="color:#ff4401;font-style:normal;font-size:15px;font-weight:bold;" id="count">0</i>件</td>
	 			<td class="gd5" >总价<i style="color:#ff4401;font-style:normal;font-size:15px;font-weight:bold;">￥<em style="font-style:normal;" id="total_price" ><input type="text" name="price_total" class="priceTotal"  value="123"  />0.00</em><input type="hidden" name="price_total" class="priceTotal"  value=""  /></i></td>
	 			<td class="gd6" >
		 			<input type="submit" id="pay" name="pay" value="创建订单"  />
	 			</td>
	 		</tr>
	 	</table >
	 	</form>
 	</div>
 </div>
